package cn.tedu.dimanage.information.webapi.controller;


import cn.tedu.dimanage.common.web.JsonResult;
import cn.tedu.dimanage.information.service.IInformationService;
import cn.tedu.dimanage.pojo.dto.InformationDTO;
import cn.tedu.dimanage.pojo.vo.InformationSimpleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/information" , produces = "application/json;charset=utf-8")
public class InformationController {

    @Autowired
    IInformationService service;

    @RequestMapping("/add-new")
    public JsonResult<Void> addNew(@Validated InformationDTO informationDTO){
        service.addNew(informationDTO);

        return JsonResult.ok();
    }

    @RequestMapping("/select-List")
    public JsonResult<List<InformationSimpleVO>> selectList(){
        List<InformationSimpleVO> ListVO = service.selectList();
        return JsonResult.ok(ListVO);
    }

    @RequestMapping("/deleteById")
    public JsonResult<Void> deleteById(Long id){
        service.deleteById(id);
        return JsonResult.ok();
    }

    @RequestMapping("/selectById")
    public JsonResult<InformationSimpleVO> selectById(Long id){
        InformationSimpleVO selectVO = service.selectById(id);
        return JsonResult.ok(selectVO);
    }

    @RequestMapping("/updateById")
    public JsonResult<Void> updateById(InformationDTO informationDTO){
        service.updateById(informationDTO);
        return JsonResult.ok();

    }

    @RequestMapping("/selectByTitle")
    public JsonResult<InformationSimpleVO> selectByTitle(String title){
        InformationSimpleVO query = service.selectByTitle(title);
        return JsonResult.ok(query);
    }


}
